﻿using System;
using System.IO;

namespace Rosetta.Default.AddIns.IO
{
    public class FileOutputter : Outputter
    {
        #region Constructors

        public FileOutputter()
            : base("File Outputter")
        {
            Category = "IO";

            Add<FileInfo, string>("FromString", FromString, "file", "contents");
            Add<FileInfo, DirectoryInfo>("MoveTo", MoveTo, "file", "directory");
        }

        #endregion

        #region Class Methods

        private static void FromString([NotNull] FileInfo file, [NotNull] string contents)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (contents == null)
            {
                throw new ArgumentNullException("contents");
            }

            File.WriteAllText(file.FullName, contents);
        }

        private static void MoveTo([NotNull] FileInfo file, [NotNull] DirectoryInfo directory)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            file.MoveTo(directory.FullName);
        }

        #endregion
    }
}